package com.zhao.shiyuanbaoyou.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhao.shiyuanbaoyou.R;
import com.zhao.shiyuanbaoyou.adapter.WorthAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 张昭 on 2016/11/12.
 */

public class WorthFragment extends Fragment{
    private Context mContext;
    private TabLayout tabLayout_worth;
    private ViewPager viewPager_worth;
    //申明适配器
    private WorthAdapter mAdapter;
    //申明集合
    private List<Fragment> mList = new ArrayList<>();
    //申明顶部导航条数组
    private String[] mArrTabTitle = null;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=getActivity();
        mArrTabTitle=getResources().getStringArray(R.array.arrWorthTabTitles);
        for (int i = 0; i < mArrTabTitle.length; i++) {
            WorthFragmentItem worthFragmentItem=new WorthFragmentItem(i);
            mList.add(worthFragmentItem);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_worth,container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout_worth= (TabLayout) view.findViewById(R.id.tablayout_fragment_worth_table);
        viewPager_worth= (ViewPager) view.findViewById(R.id.viewpager_fragment_worth);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mAdapter=new WorthAdapter(mList,getActivity().getSupportFragmentManager(),mArrTabTitle);
        viewPager_worth.setAdapter(mAdapter);
        tabLayout_worth.setupWithViewPager(viewPager_worth);
    }
}
